﻿$(function () {
    getValue();
    setLogin();
    $("a[name='produce']").live("click", function () {
        $.mobile.changePage('detail.html?id=' + $(this).attr("val"), { changeHash: true });
    });
});

function setLogin() {
    var login = location.href.split("result=");
    if (typeof (login[1]) != "undefined" && login[1] != "") {
        var json = eval("(" + Base64.decode(login[1]) + ")");
        setCookieDay("uid", json.data.uid, 1);
    }
}

function getValue() {
    $.mobile.showPageLoadingMsg();
    $.ajax({
        type: "get",
        async: true,
        url: apihost + "/index/wap",
        dataType: "json",
        ceche: true,
        data: { order: 1, key: apikey },
        jsonp: "data",
        jsonpCallback: "success_jsonpCallback",
        success: function (json) {
            var indexnew = json.data.index_new;
            var indexhot = json.data.index_hot;
            var indexrecommend = json.data.index_recommend;
            $("#rq_indexnew").append(setValue(indexnew));
            $("#rq_indexhot").append(setValue(indexhot));
            $("#rq_indexrecommend").append(setValue(indexrecommend));
        },
        error: function () {
        },
        complete: function () {
            $.mobile.hidePageLoadingMsg();
        }
    });
}

function setValue(data) {
    if (data == null) return "";
    var temp = '<div class="contentdetail">';
    temp += '<div class="biglist">';
    temp += '<a val="' + data[0].id + '" name="produce" href="#"><img src="' + data[0].simg + '" />';
    //temp += '<div class="title">' + data[0].title + '</div>';
    temp += '</a></div>';
    temp += '<div class="smalllist">';
    if (typeof (data[1]) != "undefined") {
        temp += '<div class="smalldetail smalldetailleft">';
        temp += '<a val="' + data[1].id + '" name="produce" href="#"><img src="' + data[1].simg + '" />';
        //temp += '<div class="title">' + data[1].title + '</div>';
        temp += '</a></div>';
    }
    if (typeof(data[2]) != "undefined") {
        temp += '<div class="smalldetail smalldetailright">';
        temp += '<a val="' + data[2].id + '" name="produce" href="#"><img src="' + data[2].simg + '" />';
        //temp += '<div class="title">' + data[2].title + '</div>';
        temp += '</a></div>';
    }
    temp += '<div style="clear: both;"></div>';
    if (typeof(data[3]) != "undefined") {
        temp += '<div class="smalldetail smalldetailleft">';
        temp += '<a val="' + data[3].id + '" name="produce" href="#"><img src="' + data[3].simg + '" />';
        //temp += '<div class="title">' + data[3].title + '</div>';
        temp += '</a></div>';
    }
    if (typeof(data[4]) != "undefined") {
        temp += '<div class="smalldetail smalldetailright">';
        temp += '<a val="' + data[4].id + '" name="produce" href="#"><img src="' + data[4].simg + '" />';
        //temp += '<div class="title">' + data[4].title + '</div>';
        temp += '</a></div>';
    }
    temp += '<div style="clear: both;"></div>';
    temp += '</div>';
    temp += '</div>';
    return temp;
}